package blog.service.impl;

import blog.entity.Menu;
import blog.mapper.MenuMapper;
import blog.service.MenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class MenuServiceImpl implements MenuService {
    @Resource
    private MenuMapper menuMapper;
    @Override
    public List<Menu> getMenuList() {
        return menuMapper.getMenuList();
    }

    @Override
    public void deleteMenuById(Integer id) {
        menuMapper.deleteMenuById(id);
    }

    @Override
    public Menu getMenuById(Integer id) {
        return menuMapper.getMenuById(id);
    }

    @Override
    public void updateMenu(Menu menu) {
        menuMapper.updateMenu(menu);
    }

    @Override
    public int getMaxOrderOfLevel(Integer menuLevel) {
        return menuMapper.getMaxOrderOfLevel(menuLevel);
    }

    @Override
    public void addMenu(Menu menu) {
        int maxOrderOfLevel = getMaxOrderOfLevel(menu.getMenuLevel());
        menu.setMenuOrder(maxOrderOfLevel+1);
        menuMapper.addMenu(menu);
    }
}
